// pages/activity/sixone/upload.js
Page({
  data: {
    name: "",
    fileList: [],
    imgIds: [],
  },
  onLoad(options) {

  },
  upload(e) {
    getApp().globalData.util.imgsUpload(this, e, this.data.fileList, this.data.imgIds);
  },
  delete(e) {
    let i = e.detail.index;
    let fileList = this.data.fileList;
    let imgIds = this.data.imgIds;
    fileList.splice(i, 1);
    imgIds.splice(i, 1);
    this.setData({
      fileList: fileList,
      imgIds: imgIds
    });
  },
  submit() {
    if (this.data.imgIds.length == 0) {
      getApp().globalData.vant.toast("请上传作品");
    } else if (!this.data.name) {
      getApp().globalData.vant.toast("请输入宝宝姓名/作品名称");
    } else if (this.data.name.length > 10) {
      getApp().globalData.vant.toast("宝宝姓名/作品名称长度不能超过10个字符");
    } else {
      getApp().globalData.http.sixone_distribute({
        img: this.data.imgIds[0],
        name: this.data.name
      }).then(res => {
        getApp().globalData.vant.toast({
          type: "success",
          forbidClick: true,
          message: "提交成功",
          onClose: () => {
            wx.navigateBack({
              success: function (e) {
                var page = getCurrentPages().pop();
                if (page == undefined || page == null) return;
                page.onLoad();
              }
            });
          }
        });
      }).catch(e => {
        getApp().globalData.vant.toast.fail(e.msg);
      });
    }
  }
})